
#include <cppunit/TestResult.h>
#include <cppunit/TestResultCollector.h>
#include <cppunit/TextOutputter.h>
#include <cppunit/TestRunner.h>
#include <cppunit/extensions/HelperMacros.h>

#include <string>

#include	"common/packet.hpp"

using namespace	ant;

// 定义测试类
class PacketIDTest : public CppUnit::TestFixture
{
     CPPUNIT_TEST_SUITE(PacketIDTest);  // 定义测试包
     CPPUNIT_TEST(testCompare);  
     CPPUNIT_TEST(testEmpty);  
     CPPUNIT_TEST_SUITE_END();  // 结束测试包定义
    
public:
    void setUp(); // 初始化
    void tearDown(); // 清理

    void testCompare(); 
    void testEmpty(); 

private	:
	
};


///////////////////////////////////////////////////////////////////////
//

CPPUNIT_TEST_SUITE_REGISTRATION(PacketIDTest); // 自动注册测试包
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(PacketIDTest, "alltest");

void 
PacketIDTest::setUp() // 初始化
{
}

void 
PacketIDTest::tearDown() // 清理
{
}

void 
PacketIDTest::testCompare() 
{
	Packet::packet_id_type	a(0, 0);
	Packet::packet_id_type	b(1, 0);
	Packet::packet_id_type	c(0, 1);
	Packet::packet_id_type	d(1, 1);

	Packet::packet_id_type	e(1, 2);
	Packet::packet_id_type	f(2, 1);

	CPPUNIT_ASSERT( a < b );
	CPPUNIT_ASSERT( a < c );
	CPPUNIT_ASSERT( a < d );
	CPPUNIT_ASSERT( c < b );
	CPPUNIT_ASSERT( b < d );
	CPPUNIT_ASSERT( c < d );

	CPPUNIT_ASSERT( d < e );
	CPPUNIT_ASSERT( d < f );
	CPPUNIT_ASSERT( e < f );

	CPPUNIT_ASSERT( !(e == f) );

	Packet::packet_id_type	g(e);
	CPPUNIT_ASSERT( e == g );
	CPPUNIT_ASSERT( f != g );
}

void 
PacketIDTest::testEmpty() 
{
	Packet::packet_id_type	a(0, 0);
	Packet::packet_id_type	b(1, 0);
	Packet::packet_id_type	c(0, 1);
	Packet::packet_id_type	d(1, 1);

	CPPUNIT_ASSERT(a.empty());
	CPPUNIT_ASSERT(b.empty());
	CPPUNIT_ASSERT(c.empty());
	CPPUNIT_ASSERT(!d.empty());

	CPPUNIT_ASSERT_EQUAL(true, a.empty());
	CPPUNIT_ASSERT_EQUAL(true, b.empty());
	CPPUNIT_ASSERT_EQUAL(true, c.empty());
	CPPUNIT_ASSERT_EQUAL(false, d.empty());
}



